print("简单的if分支")
local x = 10
print(x)
if x > 0 then
   print("x is a positive number")
end

print()

print("if-else分支")
local x = 11
print(x)
if x > 0 then
   print("x is a positive number")
else
   print("x is a non-positive number")
end

print()
print("多分支if-elseif-else")
local score = 90
print(score)
if score == 100 then
   print("very good! your socre is 100")
elseif score >= 60 then
   print("congratulations, you have passed it.")
else
   print("sorry, you do not pass the exam!")
end

print()

print("while循环")
local x = 1
local sum = 0
while x <= 5 do
   sum = sum + x
   x = x + 1
end
print(sum)

print()

print("for循环")
print([[
for var = begin, finish, step do
    body
end
]])
local t = {1, 3, 5, 8, 11, 18, 21}

local i
for i, v in ipairs(t) do
   if v == 11 then
	  print("index[" .. i .. "] have right value[11]")
	  break
   end
end

print("再来一个for的例子")
for i = 1, 5 do
   print(i)
end

print("再来一个带步长的for例子")
for i = 1, 10, 2 do
   print(i)
end

print("for遍历数组")
local a = {"a", "b", "c", "d"}
for i, v in ipairs(a) do
   print("index:", i, " value:", v)
end

print("for遍历字典")
local b = {
   name = "lavenliu",
   age = 23,
   sex = 1
}
for k in pairs(b) do
   print(k)
end

for k, v in pairs(b) do
   print("key is:", k, " value is:", b[k])
end


print()

print("repeat控制结构")
--[[
local x = 10
repeat
   print(x)
until false
]]--

